<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qevent.cpp -->
  <title>QFileOpenEvent Class | Qt GUI 5.14.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QFileOpenEvent</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#macos-example">macOS Example</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QFileOpenEvent Class</h1>
<!-- $$$QFileOpenEvent-brief -->
<p>The QFileOpenEvent class provides an event that will be sent when there is a request to open a file or a URL. <a href="#details">More...</a></p>
<!-- @@@QFileOpenEvent -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QFileOpenEvent&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qevent.html">QEvent</a></td></tr></table></div><ul>
<li><a href="qfileopenevent-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qfileopenevent.html#file">file</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qfileopenevent.html#openFile">openFile</a></b>(QFile &amp;<i>file</i>, QIODevice::OpenMode <i>flags</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QUrl </td><td class="memItemRight bottomAlign"><b><a href="qfileopenevent.html#url">url</a></b>() const</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QFileOpenEvent-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>File open events will be sent to the <a href="../qtcore/qcoreapplication.html#instance">QApplication::instance</a>() when the operating system requests that a file or URL should be opened. This is a high-level event that can be caused by different user actions depending on the user's desktop environment; for example, double clicking on an file icon in the Finder on macOS.</p>
<p>This event is only used to notify the application of a request. It may be safely ignored.</p>
<p><b>Note: </b>This class is currently supported for macOS only.</p><a name="macos-example"></a>
<h3 id="macos-example">macOS Example</h3>
<p>In order to trigger the event on macOS, the application must be configured to let the OS know what kind of file(s) it should react on.</p>
<p>For example, the following <code>Info.plist</code> file declares that the application can act as a viewer for files with a PNG extension:</p>
<pre class="cpp">

  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
  &lt;plist version=&quot;1.0&quot;&gt;
  &lt;dict&gt;
      &lt;key&gt;CFBundleDocumentTypes&lt;/key&gt;
      &lt;array&gt;
          &lt;dict&gt;
              &lt;key&gt;CFBundleTypeExtensions&lt;/key&gt;
              &lt;array&gt;
                  &lt;string&gt;png&lt;/string&gt;
              &lt;/array&gt;
              &lt;key&gt;CFBundleTypeRole&lt;/key&gt;
              &lt;string&gt;Viewer&lt;/string&gt;
          &lt;/dict&gt;
      &lt;/array&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;

</pre>
<p>The following implementation of a <a href="../qtwidgets/qapplication.html">QApplication</a> subclass prints the path to the file that was, for example, dropped on the Dock icon of the application.</p>
<pre class="cpp">

  <span class="preprocessor">#include &lt;QApplication&gt;</span>
  <span class="preprocessor">#include &lt;QFileOpenEvent&gt;</span>
  <span class="preprocessor">#include &lt;QtDebug&gt;</span>

  <span class="keyword">class</span> MyApplication : <span class="keyword">public</span> <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span>
  {
  <span class="keyword">public</span>:
      MyApplication(<span class="type">int</span> <span class="operator">&amp;</span>argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv)
          : <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span>(argc<span class="operator">,</span> argv)
      {
      }

      bool event(<span class="type"><a href="../qtcore/qevent.html#QEvent">QEvent</a></span> <span class="operator">*</span>event) override
      {
          <span class="keyword">if</span> (event<span class="operator">-</span><span class="operator">&gt;</span>type() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qevent.html#QEvent">QEvent</a></span><span class="operator">::</span>FileOpen) {
              <span class="type">QFileOpenEvent</span> <span class="operator">*</span>openEvent <span class="operator">=</span> <span class="keyword">static_cast</span><span class="operator">&lt;</span><span class="type">QFileOpenEvent</span> <span class="operator">*</span><span class="operator">&gt;</span>(event);
              <a href="../qtcore/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Open file&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> openEvent<span class="operator">-</span><span class="operator">&gt;</span>file();
          }

          <span class="keyword">return</span> <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span><span class="operator">::</span>event(event);
      }
  };

</pre>
</div>
<!-- @@@QFileOpenEvent -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$file[overload1]$$$file -->
<h3 class="fn" id="file"><a name="file"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QFileOpenEvent::<span class="name">file</span>() const</h3>
<p>Returns the file that is being opened.</p>
<!-- @@@file -->
<!-- $$$openFile[overload1]$$$openFileQFile&QIODevice::OpenMode -->
<h3 class="fn" id="openFile"><a name="openFile"></a><span class="type">bool</span> QFileOpenEvent::<span class="name">openFile</span>(<span class="type"><a href="../qtcore/qfile.html">QFile</a></span> &amp;<i>file</i>, <span class="type"><a href="../qtcore/qiodevice.html#OpenModeFlag-enum">QIODevice::OpenMode</a></span> <i>flags</i>) const</h3>
<p>Opens a <a href="../qtcore/qfile.html">QFile</a> on the <i>file</i> referenced by this event in the mode specified by <i>flags</i>. Returns <code>true</code> if successful; otherwise returns <code>false</code>.</p>
<p>This is necessary as some files cannot be opened by name, but require specific information stored in this event.</p>
<p>This function was introduced in Qt 4.8.</p>
<!-- @@@openFile -->
<!-- $$$url[overload1]$$$url -->
<h3 class="fn" id="url"><a name="url"></a><span class="type"><a href="../qtcore/qurl.html">QUrl</a></span> QFileOpenEvent::<span class="name">url</span>() const</h3>
<p>Returns the url that is being opened.</p>
<p>This function was introduced in Qt 4.6.</p>
<!-- @@@url -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
